******************************************************************************************************************************
** PAPER: Revealing the Zone Of Possible Agreement between parties in conflict: an application to Israeli-Palestinian peace agreements, by Elisa Cavatorta, Benjamin Groom and Gilead Sher
******************************************************************************************************************************
************************************************  PALESTINIANS DATA   ************************************************************
******************************************************************************************************************************
frame create rankingdataPAL
frame change rankingdataPAL


global rootfolder "...\Replication"

* Load the data
use "$rootfolder\Data\Palestinians_ranking_data.dta"


* Rank- Ordered Logit estimation
* Sample: Representative sample with a minimum task's completion time of 240 seconds
    *Options: reverse --> specifies that in the preference order, a higher number means a less attractive alternative.  The default is that higher values indicate more attractive alternatives.  

rologit rank a-h  , group(player_id) reverse vce(cluster player_id)
estimates store Palestine
predict P_stdp  if e(sample), stdp
matrix P_V = e(V)


* Recover coefficients as scalar
foreach v of varlist a b c d e f g h  {
	gen _bAR`v' = _b[`v']
	if abs(_b[`v']) > 1.96*(_se[`v']) {
		scalar _bAR`v' = _b[`v']
	}
	else {
		scalar _bAR`v' = 0
	}
}

matrix P_betas = e(b)

*********************************************************************************
***************************** HETEROGENEITY *************************************
*********************************************************************************
* GEOGRAPHICAL AREA: West Bank and Gaza Strip
rologit rank a-h  if d03==0, group(player_id) reverse vce(cluster player_id)
est store WestBank

* Recover coefficients as scalar
foreach v of varlist a b c d e f g h {
	 gen _bAR_WB_`v' = _b[`v']
	if abs(_b[`v']) > 1.96*(_se[`v']) {
		scalar _bAR_WB_`v' = _b[`v']
	}
	else {
		scalar _bAR_WB_`v' = 0
	}
}

rologit rank a-h  if d03==1, group(player_id) reverse vce(cluster player_id)
est store Gaza

* Recover coefficients as scalar
foreach v of varlist a b c d e f g h {
	 gen _bAR_GS_`v' = _b[`v']
	if abs(_b[`v']) > 1.96*(_se[`v']) {
		scalar _bAR_GS_`v' = _b[`v']
	}
	else {
		scalar _bAR_GS_`v' = 0
	}
}

* Fig. SI.6. Relative strengths of preference for components in sub-group of Palestinians by region
* run "$rootfolder\Dofiles\Figure_SI.6.do" 


* BY GENDER 
* Palestinians 

rologit rank a-h  if gender==0, group(player_id) reverse vce(cluster player_id)
est store Palestine_women
* Recover coefficients as scalar
foreach v of varlist a b c d e f g h {
	 gen _bAR_fem_`v' = _b[`v']
	if abs(_b[`v']) > 1.96*(_se[`v']) {
		scalar _bAR_fem_`v' = _b[`v']
	}
	else {
		scalar _bAR_fem_`v' = 0
	}
}


rologit rank a-h  if gender==1, group(player_id) reverse vce(cluster player_id)
est store Palestine_men
* Recover coefficients as scalar
scalar ba = _b[a]
scalar sea = _se[a]
scalar list 
foreach v of varlist a b c d e f g h {
	 gen _bAR_men_`v' = _b[`v']
	if abs(_b[`v']) > 1.96*(_se[`v']) {
		scalar _bAR_men_`v' = _b[`v']
	}
	else {
		scalar _bAR_men_`v' = 0
	}
}


* test the differences in each component
rologit rank a-h i.gender#(a-h), group(player_id) reverse vce(cluster player_id)


* BY AGE
sum age, det
rologit rank a-h  if age >=18 & age<=29, group(player_id) reverse vce(cluster player_id)
est store Palestine_18_29
foreach v of varlist a b c d e f g h {
	 gen _bAR_29_`v' = _b[`v']
	if abs(_b[`v']) > 1.96*(_se[`v']) {
		scalar _bAR_29_`v' = _b[`v']
	}
	else {
		scalar _bAR_29_`v' = 0
	}
}


rologit rank a-h  if age >=30 & age<=49, group(player_id) reverse vce(cluster player_id)
est store Palestine_30_49
foreach v of varlist a b c d e f g h {
	 gen _bAR_49_`v' = _b[`v']
	if abs(_b[`v']) > 1.96*(_se[`v']) {
		scalar _bAR_49_`v' = _b[`v']
	}
	else {
		scalar _bAR_49_`v' = 0
	}
}


rologit rank a-h  if age >=50 & age<=120, group(player_id) reverse vce(cluster player_id)
est store Palestine_50
foreach v of varlist a b c d e f g h {
	 gen _bAR_50_`v' = _b[`v']
	if abs(_b[`v']) > 1.96*(_se[`v']) {
		scalar _bAR_50_`v' = _b[`v']
	}
	else {
		scalar _bAR_50_`v' = 0
	}
}

